﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace Baubixinh_client
{
    public partial class frmCustomerReport : DevExpress.XtraEditors.XtraForm
    {
        public frmCustomerReport()
        {
            InitializeComponent();
        }

        private void frmCustomerReport_Load(object sender, EventArgs e)
        {
            try
            {
                DataTable objCuahang = clsDbAccess.fncGetAttributeValue(Program.gobjDb, clsEnum.ATTRIBUTE.STORE);
                DataTable objKhachHang = clsDbAccess.fncGetCustomerTotalOrderValue(Program.gobjDb);
                DataTable objNhanVien = clsDbAccess.fncGetAttributeValue(Program.gobjDb, clsEnum.ATTRIBUTE.STAFF);

                lokCuaHang.DataSource = objCuahang;
                lokNguoiBan.DataSource = objNhanVien;
                grdControlKhachHang.DataSource = objKhachHang;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }             
        }

        private void grdControlKhachHang_Click(object sender, EventArgs e)
        {
            try
            {
                string strCusName;
                string strCusEmail;
                string strCusPhone;
                DataTable objDonHang;

                strCusName = clsCommon.fncCnvNullToString(dgvKhachHang.GetFocusedRowCellValue(colTen_khach));
                strCusEmail = clsCommon.fncCnvNullToString(dgvKhachHang.GetFocusedRowCellValue(colEmail));
                strCusPhone = clsCommon.fncCnvNullToString(dgvKhachHang.GetFocusedRowCellValue(colSdt));

                objDonHang = clsDbAccess.fncGetCustomerOrders(Program.gobjDb, strCusName, strCusEmail, strCusPhone);
                grdControlDonHang.DataSource = objDonHang;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }
    }
}